/**
 * created by 小卷毛, 2023-05-26
 * Copyright (c) 2023, 416143467@qq.com All Rights Reserved.
 * #                   *********                            #
 * #                  ************                          #
 * #                  *************                         #
 * #                 **  ***********                        #
 * #                ***  ****** *****                       #
 * #                *** *******   ****                      #
 * #               ***  ********** ****                     #
 * #              ****  *********** ****                    #
 * #            *****   ***********  *****                  #
 * #           ******   *** ********   *****                #
 * #           *****   ***   ********   ******              #
 * #          ******   ***  ***********   ******            #
 * #         ******   **** **************  ******           #
 * #        *******  ********************* *******          #
 * #        *******  ******************************         #
 * #       *******  ****** ***************** *******        #
 * #       *******  ****** ****** *********   ******        #
 * #       *******    **  ******   ******     ******        #
 * #       *******        ******    *****     *****         #
 * #        ******        *****     *****     ****          #
 * #         *****        ****      *****     ***           #
 * #          *****       ***        ***      *             #
 * #            **       ****        ****                   #
 */
package com.rzico.sbl.picture

import android.content.Context
import com.luck.picture.lib.config.PictureMimeType
import com.luck.picture.lib.style.BottomNavBarStyle
import com.luck.picture.lib.style.PictureSelectorStyle
import com.luck.picture.lib.style.SelectMainStyle
import com.luck.picture.lib.style.TitleBarStyle
import com.rzico.sbl.R
import com.xinnuo.common.extend.getColorEx
import com.yalantis.ucrop.UCrop

/**
 * 描 述：PictureSelector主题样式设置
 * 作 者：小卷毛  2023-05-26 10:33
 * 修改描述：
 * 修 改 人：
 * 修改版本：
 */

/**
 * 图片列表样式设置
 */
fun Context.buildThemeStyle() =
    PictureSelectorStyle().also {
        it.titleBarStyle = TitleBarStyle().apply {
            titleBackgroundColor = getColorEx(R.color.colorAccent)
        }

        it.bottomBarStyle = BottomNavBarStyle().apply {
            bottomPreviewNormalTextColor = getColorEx(R.color.light)
            bottomPreviewSelectTextColor = getColorEx(R.color.colorAccent)
            bottomNarBarBackgroundColor = getColorEx(R.color.white)
            bottomSelectNumResources = R.drawable.picture_num_oval_selected
            bottomEditorTextColor = getColorEx(R.color.gray)
            bottomOriginalTextColor = getColorEx(R.color.gray)
        }

        it.selectMainStyle = SelectMainStyle().apply {
            statusBarColor = getColorEx(R.color.colorAccent)
            mainListBackgroundColor = getColorEx(R.color.background)
            isSelectNumberStyle = true
            isPreviewSelectNumberStyle = true
            selectBackground = R.drawable.picture_num_oval_selector
            previewSelectBackground = R.drawable.picture_preview_num_oval_selector

            selectNormalTextColor = getColorEx(R.color.light)
            selectTextColor = getColorEx(R.color.colorAccent)
            selectText = getString(R.string.ps_completed)
        }
    }

/**
 * 剪切页面样式设置
 */
fun Context.buildCropOption(
    isHiddenControl: Boolean = true,
    isFreeCropEnable: Boolean = false,
    isShowFrame: Boolean = true,
    isShowGrid: Boolean = true,
    isCircleCrop: Boolean = true,
    aspectRatioX: Float = 1f,
    aspectRatioY: Float = 1f,
    isDragCenter: Boolean = false,
    skipMimeType: Array<String> = arrayOf(
        PictureMimeType.ofGIF(),
        PictureMimeType.ofWEBP()
    ),
    isSkipCrop: Boolean = true,
    isDarkStatus:Boolean = false,
) =
    UCrop.Options().apply {
        // 裁剪菜单栏
        setHideBottomControls(isHiddenControl)
        // 裁剪图片拖动
        setFreeStyleCropEnabled(isFreeCropEnable)
        // 裁剪边框
        setShowCropFrame(isShowFrame)
        // 裁剪框网格
        setShowCropGrid(isShowGrid)
        // 裁剪圆形头像
        setCircleDimmedLayer(isCircleCrop)
        // 裁剪比例
        withAspectRatio(aspectRatioX, aspectRatioY)
        // 图片是否跟随裁剪框居中
        isCropDragSmoothToCenter(isDragCenter)
        // 跳过裁剪的资源类型
        setSkipCropMimeType(*skipMimeType)
        // 是否禁止裁剪gif和webp
        isForbidCropGifWebp(skipMimeType.isNotEmpty())
        // 多图裁剪时是否支持跳过
        isForbidSkipMultipleCrop(isSkipCrop)
        // 裁剪输出质量，0~100
        setCompressionQuality(90)

        setMaxScaleMultiplier(100f)
        isDarkStatusBarBlack(isDarkStatus)
        setStatusBarColor(getColorEx(R.color.colorAccent))
        setToolbarColor(getColorEx(R.color.colorAccent))
        setToolbarWidgetColor(getColorEx(R.color.white))
    }